package TangramCore;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class Poloha{
  public boolean flip;
  public double posunX;
  public double posunY;
  public double otoceni;
  public int zOrder;

  public Poloha() {
    flip = false;
    posunX = posunY = otoceni = zOrder = 0;
  }

  public Poloha(double a, double x, double y, boolean f, int z) {
    flip = f;
    posunX = x;
    posunY = y;
    otoceni = Math.PI* a / 180;
    zOrder = z;
  }

  public Poloha(Poloha p){
    copyFrom(p);
  }

  public boolean equals(Poloha p){
    return p.flip == flip && p.otoceni==otoceni && p.posunX==posunX && p.posunY==posunY;
  }

  public boolean equals(Poloha p, double tol, double tola){
    return p.flip == flip && Math.abs(p.otoceni-otoceni)<tola && Math.abs(p.posunX-posunX)<tol && Math.abs(p.posunY-posunY)<tol;
  }

  void copyFrom(Poloha p){
    flip = p.flip;
    posunX = p.posunX;
    posunY = p.posunY;
    otoceni = p.otoceni;
    zOrder = p.zOrder;
  }

  void saveToFile(DataOutputStream out) throws IOException{
    out.writeDouble(posunX);
    out.writeDouble(posunY);
    out.writeDouble(otoceni);
    out.writeBoolean(flip);
    out.writeInt(zOrder);
    out.flush();
  }

  void readFromFile(DataInputStream in) throws IOException{
    posunX = in.readDouble();
    posunY = in.readDouble();
    otoceni = in.readDouble();
    flip = in.readBoolean();
    zOrder = in.readInt();
  }

  @Override
  public String toString(){
    return String.format("{[%f, %f], %f, %b}", posunX, posunY, otoceni, flip);
  }
  /*static Point2D[] newPoints(int typ){
    Point2D p[] = new Point2D[dilkyOrig[typ].length];
    double b[][]=dilkyOrig[typ];
    for(int i=0;i<p.length;i++)
      p[i] = new Point2D(b[i][0],b[i][1]);
    return p;
  }


  static void setPoints(Point2D[] p, int typ){
    double b[][]=dilkyOrig[typ];
    for(int i=0;i<b.length;i++)
      p[i].setCoordinates(b[i][0],b[i][1]);
  }*/

  /*static Poloha[] getMassPolohy(){
    Poloha p[] = {
	new Poloha(TROJUHELNIK_VELKY, 0, 3, 5, false),
	new Poloha(TROJUHELNIK_VELKY, 0, 7, 5, false),
	new Poloha(TROJUHELNIK_STREDNI, 0, 10, 5, false),
	new Poloha(CTVEREC, 0, 14, 5, false),
	new Poloha(KOSODELNIK, 0, 17, 5, false),
	new Poloha(TROJUHELNIK_MALY, 0, 20, 5, false),
	new Poloha(TROJUHELNIK_MALY, 0, 22, 5, false)
    };
    return p;
  }
  static Poloha[] getCtverecPolohy(){
    Poloha p[] = {
	new Poloha(TROJUHELNIK_VELKY, -90, 4, 6, false),
	new Poloha(TROJUHELNIK_VELKY, -180, 6, 4, false),
	new Poloha(TROJUHELNIK_STREDNI, 0, 1, 1, false),
	new Poloha(CTVEREC, 90, 5, 1, false),
	new Poloha(KOSODELNIK, 0, 2, 4, false),
	new Poloha(TROJUHELNIK_MALY, 0, 1, 6, false),
	new Poloha(TROJUHELNIK_MALY, 90, 4, 3, false)
    };
    return p;
  }*/

  /*static Dilek[] getDilky (Poloha p[]){
    Dilek d[] = new Dilek[p.length];
    for (int i = 0; i < p.length; i++){
      d[i] = new Dilek(p[i]);
    }
    return d;
  }*/

/*  static Dilek[] getMass(){
    return getDilky(getMassPolohy());
  }
  static Dilek[] getCtverec(){
    return getDilky(getCtverecPolohy());
  }*/

}
